package com.ourteam.system.api;

import org.apache.commons.lang.StringUtils;

import com.ourteam.frame.web.AbstractSearchModel;
import com.ourteam.system.dao.SysDepartmentDAOQueryBean;
import com.ourteam.system.domain.SystemRole;

public class SystemDepSearchModel extends AbstractSearchModel<SysDepartmentDAOQueryBean> {

	private long parentId;

	private String departmentName;

	public long getParentId() {
		return parentId;
	}

	public void setParentId(long parentId) {
		this.parentId = parentId;
	}

	public String getDepartmentName() {
		return departmentName;
	}

	public void setDepartmentName(String departmentName) {
		this.departmentName = departmentName;
	}

	@Override
	public String getMappedDAOField(String aProperty) {
		return SystemRole.getMappedDAOField(aProperty);
	}

	@Override
	protected void doBuildQueryBean(SysDepartmentDAOQueryBean queryBean) throws Exception {

		SysDepartmentDAOQueryBean.Criteria criteria = queryBean.createCriteria();

		if (this.parentId != 0) {
			criteria.andParentIdEqualTo(parentId);
		}

		if (StringUtils.isNotEmpty(departmentName)) {
			criteria.andDepartmentNameEqualTo(departmentName);
		}

		// queryBean.setSortProperty(ISysRoleDAO.DomainCode, aIsAsc);

	}
}
